package com.cy.cy2025.activity

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.cy.cy2025.R
import com.cy.cy2025.databinding.ActivityComposeNoteBinding

class ComposeNoteActivity : AppCompatActivity() {

    val binding by lazy {
        ActivityComposeNoteBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

        binding.tvNote.text =
            """
                1.UI 组件使用@Composable修饰
                
                2.纵向布局Column，横向布局Row，堆叠布局Box,占位布局Spacer
                
                3.修饰都通过modifier设置(建造模式链式调用)
                
                4.绑定livedata数据：转化成state，如：
                    val list = vm.data.observeAsState(initial = emptyList()).value
                    
                5.对应RecyclerView的LazyColumn，LazyRow
                
                6.列表项刷新时，未改变的item不重建的实践：
                    构建方法需要导入：import androidx.compose.foundation.lazy.items
                    需要提供key：LazyColumn {
                    items(items = list, key = { it }) { item -> ... }
                
                7.嵌入原生安卓View示例：（注意数据的显示在update里现实，第一次显示时就会调用一次）
                    Column(modifier = Modifier.padding(0.dp, 40.dp, 0.dp, 0.dp)) {
                          val show = vm.show.observeAsState(initial = false).value
                                AndroidView<ImageView>(
                                    modifier = Modifier.fillMaxWidth().height(300.dp),
                                    factory = { context -> ImageView(context)},
                                    update = { 
                                        view -> 
                                        LogUtil.d(TAG, "view更新") 
                                        if (show) {
                                            view.setImageResource(R.drawable.ic_launcher)
                                        }
                                    }
                            )
                            ...
                8.同时设置圆角，背景，边框 示例（注意调用顺序）:
                    modifier = Modifier
                        .size(100.dp)
                        .clip(RoundedCornerShape(10.dp, 20.dp, 20.dp, 10.dp))
                        .background(Color.Red)
                        .border(2.dp, Color.Blue, shape = RoundedCornerShape(10.dp, 20.dp, 20.dp, 10.dp))
                        
                9.局部变量保存
                    val x = remember { mutableIntStateOf(0) }
            """.trimIndent()
    }
}